<template>
    <div>
        <h1>房号信息更新</h1>
        <table class="table">
            <tbody>
                <tr>
                    <th>房号</th>
                    <th>
                        <input type="text" v-model="data.StoreId">
                    </th>
                </tr>
                <tr>
                    <th>房号名称</th>
                    <th>
                        <input type="text" v-model="data.Name">
                    </th>
                </tr>
                <tr>
                    <th>账号</th>
                    <th>
                        <input type="text" v-model="data.UserZH">
                    </th>
                </tr>
                <tr>
                    <th>密码</th>
                    <th>
                        <input type="password" v-model="data.UserPwd">
                    </th>
                </tr>
                <tr>
                    <th colspan="2">
                        <input type="button" value="更新" @click="Add">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
    import { ref,onMounted } from 'vue';
    import axios from 'axios';
    import { useRouter,useRoute } from 'vue-router';
    const route = useRoute()
    const router = useRouter()
    const data = ref({
    "Id": 0,
    "StoreId": 0,
    "Name": "",
    "UserZH": "",
    "UserPwd": ""
    })
    onMounted(()=>{
        Find()
    })
    const Find=()=>{
        var vid = route.query.id;
        axios.get("https://localhost:7116/api/Store/GetStore",{params:{id:vid}}).then(res=>{
            data.value = res.data
        })
    }
    const Add=()=>{
        axios.post("https://localhost:7116/api/Store/UpdStore",data.value).then(res=>{
            if(res.data>0){
                alert('更新成功')
                router.push({path:"/Show"})
            }
            else{
                alert('更新失败')
            }
        })
    }
</script>

<style scoped>

</style>